man= []
other = []
try:
    data=open('sketch.txt')
    try:
        for each_line in data:
                (role, line_spoken) = each_line.split(':',1)
                line_spoken = line_spoken.strip() # 去除空格
                if(role == 'Man') :
                    man.append(line_spoken)
                elif role=='Other Man':
                    other.append(line_spoken)
    except ValueError:
        pass
    data.close()
except IOError:
    print('The datafile is missing')

try:
    # open() 可以设置访问模式, w表示写
    man_file = open('man_data.txt','w')
    other_file = open('other_data.txt','w')
    # print() 可以把数据写至磁盘
    print(man, file=man_file)
    print(other, file= other_file)
except IOError:
    print('File Error')
finally:
    man_file.close()
    other_file.close()

